﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Electrical;
using YArchitech.LIB;
using HYCodeBase.XmlUtility;

namespace HYElectricSetting
{
	public static class ElectricSettingData
	{
		static ElectricSettingData()
		{
			ElectricSettingData.wireSettingData = null;
			ElectricSettingData.WireSettingProcessData = null;
			ElectricSettingData.conduitSettingData = null;
			ElectricSettingData.ConduitSettingProcessData = null;
			ElectricSettingData.wireConduitSettingData = null;
			ElectricSettingData.wireConduitSettingProcessData = null;
		}

		public static List<WireSizeData> WireSettingData
		{
			get
			{
				return ElectricSettingData.wireSettingData;
			}
		}

		public static List<WireSizeData> WireSettingProcessData { get; set; }

		public static void InitWireSettingProcessData(Autodesk.Revit.DB.Document doc)
		{
			bool flag = ElectricSettingData.WireSettingProcessData != null;
			if (!flag)
			{
				ElectricSettingData.ReadWireSettingData(doc);
				ElectricSettingData.WireSettingProcessData = new List<WireSizeData>();
				foreach (WireSizeData other in ElectricSettingData.wireSettingData)
				{
					WireSizeData item = new WireSizeData(other);
					ElectricSettingData.WireSettingProcessData.Add(item);
				}
			}
		}

		public static void ReadWireSettingData(Autodesk.Revit.DB.Document doc)
		{
			bool flag = ElectricSettingData.wireSettingData != null;
			if (flag)
			{
				ElectricSettingData.wireSettingData.Clear();
			}
			else
			{
				ElectricSettingData.wireSettingData = new List<WireSizeData>();
			}
			ElectricSettingData.ReadWireTypeFromDoc(doc);
			ElectricSettingData.ReadWireSizeFromXml();
		}

		public static List<WireSizeData> ReadDefaultWireSettingData(Autodesk.Revit.DB.Document doc)
		{
			List<WireSizeData> list = new List<WireSizeData>();
			bool flag = doc == null;
			List<WireSizeData> result;
			if (flag)
			{
				result = list;
			}
			else
			{
				string defaultDataFile = ElectricSettingData.GetDefaultDataFile();
				bool flag2 = string.IsNullOrEmpty(defaultDataFile) || !File.Exists(defaultDataFile);
				if (flag2)
				{
					result = list;
				}
				else
				{
					HYCodeBase.XmlUtility.XmlHelper xmlHelper = new HYCodeBase.XmlUtility.XmlHelper(defaultDataFile, "ElectricData");
					List<XmlElement> elements = xmlHelper.GetElements("Wire");
					Transaction transaction = new Transaction(doc, "DefaultWireType");
					transaction.Start();
					try
					{
						foreach (XmlElement xmlElement in elements)
						{
							string attribute = xmlElement.GetAttribute("Name");
							WireSizeData wireSizeData = new WireSizeData();
							wireSizeData.WireType = new WireTypeData(doc, attribute);
							List<XmlElement> elements2 = HYCodeBase.XmlUtility.XmlHelper.GetElements(xmlElement);
							foreach (XmlElement xmlElement2 in elements2)
							{
								double key = Convert.ToDouble(xmlElement2.GetAttribute("Size"));
								double value = Convert.ToDouble(xmlElement2.GetAttribute("Ampacity"));
								wireSizeData.WireSizes.Add(key, value);
							}
							wireSizeData.WireSizeSorted();
							list.Add(wireSizeData);
						}
						transaction.Commit();
					}
					catch (Exception)
					{
						bool flag3 = transaction != null && (int)transaction.GetStatus() != 3;
						if (flag3)
						{
							transaction.RollBack();
						}
					}
					result = list;
				}
			}
			return result;
		}

		public static void SaveWireSettingData(Autodesk.Revit.DB.Document doc)
		{
			bool flag = doc == null || ElectricSettingData.wireSettingData == null;
			if (!flag)
			{
				bool flag2 = ElectricSettingData.WireSettingProcessData == null || ElectricSettingData.WireSettingProcessData.Count <= 0;
				if (!flag2)
				{
					ElectricSettingData.wireSettingData.Clear();
					foreach (WireSizeData other in ElectricSettingData.WireSettingProcessData)
					{
						WireSizeData item = new WireSizeData(other);
						ElectricSettingData.wireSettingData.Add(item);
					}
					ElectricSettingData.SaveWireTypeToDoc(doc);
					ElectricSettingData.SaveWireSizeToXml();
				}
			}
		}

		private static void ReadWireTypeFromDoc(Autodesk.Revit.DB.Document doc)
		{
			bool flag = doc == null || ElectricSettingData.wireSettingData == null;
			if (!flag)
			{
				WireTypeSet wireTypes = doc.Settings.ElectricalSetting.WireTypes;
				WireTypeSetIterator wireTypeSetIterator = wireTypes.ForwardIterator();
				while (wireTypeSetIterator.MoveNext())
				{
					object obj = wireTypeSetIterator.Current;
					WireType wireType = obj as WireType;
					string name = wireType.Name;
					bool flag2 = name == "默认";
					if (!flag2)
					{
						WireSizeData wireSizeData = new WireSizeData();
						wireSizeData.WireType = new WireTypeData(wireType);
						ElectricSettingData.wireSettingData.Add(wireSizeData);
					}
				}
			}
		}

		private static void ReadWireSizeFromXml()
		{
			bool flag = ElectricSettingData.wireSettingData == null;
			if (!flag)
			{
				string userDataFile = ElectricSettingData.GetUserDataFile();
				bool flag2 = string.IsNullOrEmpty(userDataFile) || !File.Exists(userDataFile);
				if (!flag2)
				{
					HYCodeBase.XmlUtility.XmlHelper xmlHelper = new HYCodeBase.XmlUtility.XmlHelper(userDataFile, "ElectricData");
					List<XmlElement> elements = xmlHelper.GetElements("Wire");
					foreach (XmlElement xmlElement in elements)
					{
						string wireTypeName = xmlElement.GetAttribute("Name");
						bool flag3 = !ElectricSettingData.wireSettingData.Exists((WireSizeData u) => u.WireType.Name == wireTypeName);
						if (!flag3)
						{
							WireSizeData wireSizeData = ElectricSettingData.wireSettingData.Find((WireSizeData u) => u.WireType.Name == wireTypeName);
							bool flag4 = wireSizeData == null;
							if (!flag4)
							{
								List<XmlElement> elements2 = HYCodeBase.XmlUtility.XmlHelper.GetElements(xmlElement);
								foreach (XmlElement xmlElement2 in elements2)
								{
									double key = Convert.ToDouble(xmlElement2.GetAttribute("Size"));
									double value = Convert.ToDouble(xmlElement2.GetAttribute("Ampacity"));
									wireSizeData.WireSizes.Add(key, value);
								}
								wireSizeData.WireSizeSorted();
							}
						}
					}
				}
			}
		}

		private static void SaveWireTypeToDoc(Autodesk.Revit.DB.Document doc)
		{
			Transaction transaction = new Transaction(doc, "NewWireType");
			transaction.Start();
			try
			{
				foreach (WireSizeData wireSizeData in ElectricSettingData.wireSettingData)
				{
					WireTypeData wireType = wireSizeData.WireType;
					bool flag = ElectricSettingData.ExistsWireType(doc, wireType.Name);
					if (!flag)
					{
						doc.Settings.ElectricalSetting.AddWireType(wireType.Name, wireType.WireMaterial, wireType.TemperatureRating, wireType.Insulation, wireType.MaxSize, wireType.NeutralMultiplier, wireType.NeutralRequired, wireType.NeutralSize, wireType.Conduit);
					}
				}
				WireTypeSet wireTypes = doc.Settings.ElectricalSetting.WireTypes;
				WireTypeSetIterator wireTypeSetIterator = wireTypes.ForwardIterator();
				while (wireTypeSetIterator.MoveNext())
				{
					WireType wireType2 = wireTypeSetIterator.Current as WireType;
					string wireTypeName = wireType2.Name;
					bool flag2 = ElectricSettingData.wireSettingData.Exists((WireSizeData wsd) => wsd.WireType.Name == wireTypeName);
					if (!flag2)
					{
						doc.Settings.ElectricalSetting.RemoveWireType(wireType2);
					}
				}
				transaction.Commit();
			}
			catch (Exception)
			{
				bool flag3 = transaction != null && (int)transaction.GetStatus() != 3;
				if (flag3)
				{
					transaction.RollBack();
				}
			}
		}

		private static void SaveWireSizeToXml()
		{
			string userDataFile = ElectricSettingData.GetUserDataFile();
			bool flag = string.IsNullOrEmpty(userDataFile) || !File.Exists(userDataFile);
			if (!flag)
			{
				HYCodeBase.XmlUtility.XmlHelper xmlHelper = new HYCodeBase.XmlUtility.XmlHelper(userDataFile, "ElectricData");
				List<XmlElement> elements = xmlHelper.GetElements("Wire");
				XmlElement xmlCurNode = xmlHelper.XmlCurNode;
				bool flag2 = xmlCurNode == null;
				if (!flag2)
				{
					foreach (WireSizeData wireSizeData in ElectricSettingData.wireSettingData)
					{
						string name = wireSizeData.WireType.Name;
						XmlElement xmlElement = ElectricSettingData.FindWireTypeNode(name, elements);
						bool flag3 = xmlElement == null;
						if (flag3)
						{
							xmlElement = HYCodeBase.XmlUtility.XmlHelper.AddElement(xmlCurNode, "WireType");
						}
						else
						{
							xmlElement.RemoveAll();
						}
						HYCodeBase.XmlUtility.XmlHelper.SetAttribute(xmlElement, "Name", name);
						foreach (KeyValuePair<double, double> keyValuePair in wireSizeData.WireSizes)
						{
							XmlElement node = HYCodeBase.XmlUtility.XmlHelper.AddElement(xmlElement, "WireSize");
							HYCodeBase.XmlUtility.XmlHelper.SetAttribute(node, "Size", keyValuePair.Key.ToString());
							HYCodeBase.XmlUtility.XmlHelper.SetAttribute(node, "Ampacity", keyValuePair.Value.ToString());
						}
					}
					xmlHelper.SaveXml("");
				}
			}
		}

		private static bool ExistsWireType(Autodesk.Revit.DB.Document doc, string wireTypeName)
		{
			WireTypeSet wireTypes = doc.Settings.ElectricalSetting.WireTypes;
			WireTypeSetIterator wireTypeSetIterator = wireTypes.ForwardIterator();
			while (wireTypeSetIterator.MoveNext())
			{
				object obj = wireTypeSetIterator.Current;
				WireType wireType = obj as WireType;
				bool flag = wireType.Name == wireTypeName;
				if (flag)
				{
					return true;
				}
			}
			return false;
		}

		private static XmlElement FindWireTypeNode(string name, List<XmlElement> xmlNodes)
		{
			bool flag = xmlNodes == null || xmlNodes.Count <= 0;
			XmlElement result;
			if (flag)
			{
				result = null;
			}
			else
			{
				foreach (XmlElement xmlElement in xmlNodes)
				{
					string attribute = xmlElement.GetAttribute("Name");
					bool flag2 = name == attribute;
					if (flag2)
					{
						return xmlElement;
					}
				}
				result = null;
			}
			return result;
		}

		public static List<ConduitTypeData> ConduitSettingData
		{
			get
			{
				return ElectricSettingData.conduitSettingData;
			}
		}

		public static List<ConduitTypeData> ConduitSettingProcessData { get; set; }

		public static void InitConduitSettingProcessData(Autodesk.Revit.DB.Document doc)
		{
			bool flag = ElectricSettingData.ConduitSettingProcessData != null;
			if (!flag)
			{
				ElectricSettingData.ReadConduitSettingData(doc);
				ElectricSettingData.ConduitSettingProcessData = new List<ConduitTypeData>();
				foreach (ConduitTypeData other in ElectricSettingData.conduitSettingData)
				{
					ConduitTypeData item = new ConduitTypeData(other);
					ElectricSettingData.ConduitSettingProcessData.Add(item);
				}
			}
		}

		public static void ReadConduitSettingData(Autodesk.Revit.DB.Document doc)
		{
			bool flag = ElectricSettingData.conduitSettingData == null;
			if (flag)
			{
				ElectricSettingData.conduitSettingData = new List<ConduitTypeData>();
			}
			else
			{
				ElectricSettingData.conduitSettingData.Clear();
			}
			ElectricSettingData.ReadConduitTypeDataFromDoc(doc);
			ElectricSettingData.ReadConduitTypeDataFromXml();
		}

		public static void SaveConduitSettingData(Autodesk.Revit.DB.Document doc)
		{
			bool flag = doc == null || ElectricSettingData.conduitSettingData == null;
			if (!flag)
			{
				bool flag2 = ElectricSettingData.ConduitSettingProcessData == null || ElectricSettingData.ConduitSettingProcessData.Count <= 0;
				if (!flag2)
				{
					ElectricSettingData.conduitSettingData.Clear();
					foreach (ConduitTypeData other in ElectricSettingData.ConduitSettingProcessData)
					{
						ConduitTypeData item = new ConduitTypeData(other);
						ElectricSettingData.conduitSettingData.Add(item);
					}
					ElectricSettingData.SaveConduitTypeDataToDoc(doc);
					ElectricSettingData.SaveConduitTypeDataToXml();
				}
			}
		}

		private static void ReadConduitTypeDataFromDoc(Autodesk.Revit.DB.Document doc)
		{
			bool flag = doc == null || ElectricSettingData.conduitSettingData == null;
			if (!flag)
			{
				FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
				ICollection<ElementId> collection = filteredElementCollector.OfClass(typeof(ConduitType)).ToElementIds();
				foreach (ElementId elementId in collection)
				{
					ConduitType conduitType = doc.GetElement(elementId) as ConduitType;
					bool flag2 = conduitType == null || !conduitType.IsWithFitting;
					if (!flag2)
					{
						ConduitTypeData conduitTypeData = new ConduitTypeData(conduitType.Name);
						conduitTypeData.Elbow = conduitType.Elbow;
						conduitTypeData.Tee = conduitType.Tee;
						conduitTypeData.Cross = conduitType.Cross;
						conduitTypeData.Transition = conduitType.Transition;
						conduitTypeData.Union = conduitType.Union;
						conduitTypeData.BaseConduitType = elementId;
						ElectricSettingData.conduitSettingData.Add(conduitTypeData);
					}
				}
			}
		}

		private static void ReadConduitTypeDataFromXml()
		{
			bool flag = ElectricSettingData.conduitSettingData == null;
			if (!flag)
			{
				string userDataFile = ElectricSettingData.GetUserDataFile();
				bool flag2 = string.IsNullOrEmpty(userDataFile) || !File.Exists(userDataFile);
				if (!flag2)
				{
					HYCodeBase.XmlUtility.XmlHelper xmlHelper = new HYCodeBase.XmlUtility.XmlHelper(userDataFile, "ElectricData");
					List<XmlElement> elements = xmlHelper.GetElements("Conduit");
					foreach (XmlElement xmlElement in elements)
					{
						string conduitTypeName = xmlElement.GetAttribute("Name");
						bool flag3 = !ElectricSettingData.conduitSettingData.Exists((ConduitTypeData u) => u.Name == conduitTypeName);
						if (!flag3)
						{
							ConduitTypeData conduitTypeData = ElectricSettingData.conduitSettingData.Find((ConduitTypeData u) => u.Name == conduitTypeName);
							bool flag4 = conduitTypeData == null;
							if (!flag4)
							{
								List<XmlElement> elements2 = HYCodeBase.XmlUtility.XmlHelper.GetElements(xmlElement);
								foreach (XmlElement xmlElement2 in elements2)
								{
									int item = Convert.ToInt32(xmlElement2.InnerText);
									conduitTypeData.SizeSet.Add(item);
								}
								conduitTypeData.SizeSet.Sort();
							}
						}
					}
				}
			}
		}

		private static void SaveConduitTypeDataToDoc(Autodesk.Revit.DB.Document doc)
		{
			Transaction transaction = new Transaction(doc, "NewConduitType");
			transaction.Start();
			try
			{
				foreach (ConduitTypeData conduitTypeData in ElectricSettingData.conduitSettingData)
				{
					ConduitType conduitType3 = ElectricSettingData.FindConduitType(doc, conduitTypeData.Name);
					bool flag = conduitType3 == null;
					if (flag)
					{
						ConduitType conduitType2 = doc.GetElement(conduitTypeData.BaseConduitType) as ConduitType;
						bool flag2 = conduitType2 == null;
						if (flag2)
						{
							continue;
						}
						conduitType3 = (conduitType2.Duplicate(conduitTypeData.Name) as ConduitType);
						bool flag3 = conduitType3 == null;
						if (flag3)
						{
							continue;
						}
					}
					conduitType3.Elbow = conduitTypeData.Elbow;
					conduitType3.Tee = conduitTypeData.Tee;
					conduitType3.Cross = conduitTypeData.Cross;
					conduitType3.Transition = conduitTypeData.Transition;
					conduitType3.Union = conduitTypeData.Union;
				}
				FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
				IList<Element> list = filteredElementCollector.OfClass(typeof(ConduitType)).ToElements();
				foreach (Element element in list)
				{
					ConduitType conduitType = element as ConduitType;
					bool flag4 = conduitType == null || !conduitType.IsWithFitting;
					if (!flag4)
					{
						bool flag5 = ElectricSettingData.conduitSettingData.Exists((ConduitTypeData ctd) => ctd.Name == conduitType.Name);
						if (!flag5)
						{
							doc.Delete(element.Id);
						}
					}
				}
				transaction.Commit();
			}
			catch (Exception ex)
			{
				bool flag6 = transaction != null && (int)transaction.GetStatus() != 3;
				if (flag6)
				{
					transaction.RollBack();
				}
			}
		}

		private static void SaveConduitTypeDataToXml()
		{
			string userDataFile = ElectricSettingData.GetUserDataFile();
			bool flag = string.IsNullOrEmpty(userDataFile) || !File.Exists(userDataFile);
			if (!flag)
			{
				HYCodeBase.XmlUtility.XmlHelper xmlHelper = new HYCodeBase.XmlUtility.XmlHelper(userDataFile, "ElectricData");
				List<XmlElement> elements = xmlHelper.GetElements("Conduit");
				XmlElement xmlCurNode = xmlHelper.XmlCurNode;
				bool flag2 = xmlCurNode == null;
				if (!flag2)
				{
					foreach (ConduitTypeData conduitTypeData in ElectricSettingData.conduitSettingData)
					{
						string name = conduitTypeData.Name;
						XmlElement xmlElement = ElectricSettingData.FindConduitTypeNode(name, elements);
						bool flag3 = xmlElement == null;
						if (flag3)
						{
							xmlElement = HYCodeBase.XmlUtility.XmlHelper.AddElement(xmlCurNode, "ConduitType");
						}
						else
						{
							xmlElement.RemoveAll();
						}
						HYCodeBase.XmlUtility.XmlHelper.SetAttribute(xmlElement, "Name", name);
						foreach (int num in conduitTypeData.SizeSet)
						{
							XmlElement node = HYCodeBase.XmlUtility.XmlHelper.AddElement(xmlElement, "Size");
							HYCodeBase.XmlUtility.XmlHelper.SetValue(node, num.ToString());
						}
					}
					xmlHelper.SaveXml("");
				}
			}
		}

		private static ConduitType FindConduitType(Autodesk.Revit.DB.Document doc, string conduitTypeName)
		{
			bool flag = doc == null || string.IsNullOrEmpty(conduitTypeName);
			ConduitType result;
			if (flag)
			{
				result = null;
			}
			else
			{
				FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc);
				IList<Element> list = filteredElementCollector.OfClass(typeof(ConduitType)).ToElements();
				foreach (Element element in list)
				{
					ConduitType conduitType = element as ConduitType;
					bool flag2 = conduitType == null || !conduitType.IsWithFitting;
					if (!flag2)
					{
						bool flag3 = conduitTypeName == conduitType.Name;
						if (flag3)
						{
							return conduitType;
						}
					}
				}
				result = null;
			}
			return result;
		}

		private static XmlElement FindConduitTypeNode(string name, List<XmlElement> xmlNodes)
		{
			bool flag = xmlNodes == null || xmlNodes.Count <= 0;
			XmlElement result;
			if (flag)
			{
				result = null;
			}
			else
			{
				foreach (XmlElement xmlElement in xmlNodes)
				{
					string attribute = xmlElement.GetAttribute("Name");
					bool flag2 = name == attribute;
					if (flag2)
					{
						return xmlElement;
					}
				}
				result = null;
			}
			return result;
		}

		public static List<WireConduitData> WireConduitSettingData
		{
			get
			{
				return ElectricSettingData.wireConduitSettingData;
			}
		}

		public static List<WireConduitData> wireConduitSettingProcessData { get; set; }

		public static void InitWireConduitSettingProcessData()
		{
			bool flag = ElectricSettingData.wireConduitSettingProcessData != null;
			if (!flag)
			{
				ElectricSettingData.ReadWireConduitSettingData();
				ElectricSettingData.wireConduitSettingProcessData = new List<WireConduitData>();
				foreach (WireConduitData other in ElectricSettingData.wireConduitSettingData)
				{
					WireConduitData item = new WireConduitData(other);
					ElectricSettingData.wireConduitSettingProcessData.Add(item);
				}
			}
		}

		public static void ReadWireConduitSettingData()
		{
			bool flag = ElectricSettingData.wireConduitSettingData == null;
			if (flag)
			{
				ElectricSettingData.wireConduitSettingData = new List<WireConduitData>();
			}
			else
			{
				ElectricSettingData.wireConduitSettingData.Clear();
			}
			string userDataFile = ElectricSettingData.GetUserDataFile();
			bool flag2 = string.IsNullOrEmpty(userDataFile) || !File.Exists(userDataFile);
			if (!flag2)
			{
				HYCodeBase.XmlUtility.XmlHelper xmlHelper = new HYCodeBase.XmlUtility.XmlHelper(userDataFile, "ElectricData");
				List<XmlElement> elements = xmlHelper.GetElements("WireConduit");
				foreach (XmlElement xmlElement in elements)
				{
					string wireType = xmlElement.GetAttribute("WireType");
					string conduitType = xmlElement.GetAttribute("ConduitType");
					bool flag3 = ElectricSettingData.wireConduitSettingData.Exists((WireConduitData u) => wireType == u.WireTypeName && conduitType == u.ConduitTypeName);
					if (!flag3)
					{
						WireConduitData wireConduitData = new WireConduitData(wireType, conduitType);
						ElectricSettingData.wireConduitSettingData.Add(wireConduitData);
						List<XmlElement> elements2 = HYCodeBase.XmlUtility.XmlHelper.GetElements(xmlElement);
						bool flag4 = elements2 == null;
						if (!flag4)
						{
							foreach (XmlElement xmlElement2 in elements2)
							{
								double key = Convert.ToDouble(xmlElement2.GetAttribute("WireSize"));
								int value = Convert.ToInt32(xmlElement2.GetAttribute("ConduitSize"));
								wireConduitData.WireConduitSet.Add(key, value);
							}
							wireConduitData.WireConduitSorted();
						}
					}
				}
			}
		}

		public static void SaveWireConduitSettingData()
		{
			bool flag = ElectricSettingData.wireConduitSettingData == null || ElectricSettingData.wireConduitSettingProcessData == null || ElectricSettingData.wireConduitSettingProcessData.Count <= 0;
			if (!flag)
			{
				ElectricSettingData.wireConduitSettingData.Clear();
				foreach (WireConduitData other in ElectricSettingData.wireConduitSettingProcessData)
				{
					WireConduitData item = new WireConduitData(other);
					ElectricSettingData.wireConduitSettingData.Add(item);
				}
				string userDataFile = ElectricSettingData.GetUserDataFile();
				bool flag2 = string.IsNullOrEmpty(userDataFile) || !File.Exists(userDataFile);
				if (!flag2)
				{
					HYCodeBase.XmlUtility.XmlHelper xmlHelper = new HYCodeBase.XmlUtility.XmlHelper(userDataFile, "ElectricData");
					List<XmlElement> elements = xmlHelper.GetElements("WireConduit");
					XmlElement xmlCurNode = xmlHelper.XmlCurNode;
					bool flag3 = xmlCurNode == null;
					if (!flag3)
					{
						xmlCurNode.RemoveAll();
						foreach (WireConduitData wireConduitData in ElectricSettingData.wireConduitSettingData)
						{
							XmlElement xmlElement = HYCodeBase.XmlUtility.XmlHelper.AddElement(xmlCurNode, "WireConduitPair");
							HYCodeBase.XmlUtility.XmlHelper.SetAttribute(xmlElement, "WireType", wireConduitData.WireTypeName);
							HYCodeBase.XmlUtility.XmlHelper.SetAttribute(xmlElement, "ConduitType", wireConduitData.ConduitTypeName);
							foreach (KeyValuePair<double, int> keyValuePair in wireConduitData.WireConduitSet)
							{
								XmlElement node = HYCodeBase.XmlUtility.XmlHelper.AddElement(xmlElement, "Pair");
								HYCodeBase.XmlUtility.XmlHelper.SetAttribute(node, "WireSize", keyValuePair.Key.ToString());
								HYCodeBase.XmlUtility.XmlHelper.SetAttribute(node, "ConduitSize", keyValuePair.Value.ToString());
							}
						}
						xmlHelper.SaveXml("");
					}
				}
			}
		}

		private static string GetTemplateDataFile()
		{
			return Path.Combine(Product.DataLocation, "ElectricalData", "ElectricSetting.xml");
		}

		private static string GetUserDataFile()
		{
			string text = Path.Combine(Product.UserDataLocation, "ElectricSetting.xml");
			bool flag = !File.Exists(text);
			if (flag)
			{
				string templateDataFile = ElectricSettingData.GetTemplateDataFile();
				bool flag2 = !File.Exists(templateDataFile);
				if (flag2)
				{
					return string.Empty;
				}
				File.Copy(templateDataFile, text);
			}
			return text;
		}

		private static string GetDefaultDataFile()
		{
			return Path.Combine(Product.DataLocation, "ElectricalData", "ElectricDefaultSetting.xml");
		}

		private static List<WireSizeData> wireSettingData = null;

		private static List<ConduitTypeData> conduitSettingData;

		private static List<WireConduitData> wireConduitSettingData;
	}
}
